// 用户相关信息
import { DO_LOGIN } from './actionTypes'
let  defaultState = {
    nickName:'',
    avatar:"",
    token:"",
    role:''
}
// 页面刷新时，取缓存 user  考虑首次打开
const user = localStorage.getItem('userInfo')?JSON.parse(localStorage.getItem('userInfo')):{}
defaultState = user
// 定义用户reducer
const userReducer = (state=defaultState,action)=>{
 
  let newState = JSON.parse(JSON.stringify(state))

  switch (action.type) {
    case DO_LOGIN:
      newState = action.userInfo;
      break;
    default:
      break;
  }
  localStorage.setItem("userInfo", JSON.stringify(newState))
  return newState
}

export default userReducer